package com.beiming.sensor

import android.app.Activity
import android.app.Application
import android.os.Bundle
import android.util.Log

/**
 * Created by lingchen on 2020/5/5. 10:30
 * mail:lingchen52@foxmail.com
 */
class App : Application() {

    val TAG = javaClass.simpleName

    override fun onCreate() {
        super.onCreate()

        registerActivityLifecycleCallback()
    }

    private fun registerActivityLifecycleCallback() {
        registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
            override fun onActivityPaused(activity: Activity) {
                Log.d(TAG, "onActivityPaused:${activity.javaClass.simpleName}")
            }

            override fun onActivityStarted(activity: Activity) {
                Log.d(TAG, "onActivityStarted:${activity.javaClass.simpleName}")
            }

            override fun onActivityDestroyed(activity: Activity) {
                Log.d(TAG, "onActivityDestroyed:${activity.javaClass.simpleName}")
                ActivityCollector.removeActivity(activity)
            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
                Log.d(TAG, "onActivitySaveInstanceState:${activity.javaClass.simpleName}")
            }

            override fun onActivityStopped(activity: Activity) {
                Log.d(TAG, "onActivityStopped:${activity.javaClass.simpleName}")
            }

            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                Log.d(TAG, "onActivityCreated:${activity.javaClass.simpleName}")
                ActivityCollector.addActivity(activity)
            }

            override fun onActivityResumed(activity: Activity) {
                Log.d(TAG, "onActivityResumed:${activity.javaClass.simpleName}")
            }
        })
    }
}